/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bionic.commands.request;

import com.bionic.commands.common.ICommand;
import com.bionic.dao.ReqestDAO;
import com.bionic.entity.Reqest;
import com.bionic.entity.Users;
import com.bionic.logic.request.RequestLogic;
import com.bionic.manager.Config;
import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Obuhov D.G.
 */
public class CRequestClose implements ICommand {

  @Override
    public String execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String page = null; 

        HttpSession session = request.getSession();
        Users user = (Users) session.getAttribute("currentUser");
        Integer someRequestId = Integer.parseInt(request.getParameter("selectedRequest"));
        if ((user!=null)&&(user.getId() != null)) {
            String closeResult = null;
            if (someRequestId == null) {
                request.setAttribute("errorMessage", "Не выбран запрос");
            } else {
              // процедура изменения статуса заявки  
              closeResult = RequestLogic.CloseRequest(someRequestId);
              request.setAttribute("errorMessage", "Не выбран запрос");
            }
            page = Config.getInstance().getProperty(Config.REQUESTS_VIEW);
        } else {
            page = Config.getInstance().getProperty(Config.LOGIN);
        }

        return page;
    }
  
}
